    void dfs(vector<int>& candidates, int pos, int sum) {
        if (sum >= target) {
            if (sum == target)
                ret.push_back(path);
            return;
        }

        for (int i = pos; i < candidates.size(); i++) {
            path.push_back(candidates[i]);
            dfs(candidates, i, sum +candidates[i]);
            path.pop_back();
        }

    }

    //
    class Solution {
    vector<vector<int>> ret;
    vector<int> path;
    int target;

public:
    vector<vector<int>> combinationSum(vector<int>& candidates, int _target) {
        target = _target;
        dfs(candidates, 0, 0);
        return ret;
    }

    void dfs(vector<int>& candidates, int pos, int sum) {
        if (sum >= target) {
            if (sum == target)
                ret.push_back(path);
            return;
        }
        if(pos==candidates.size()) return;

        for (int k = 0; k * candidates[pos] + sum <= target; k++) {
            if (k)
                path.push_back(candidates[pos]);
            dfs(candidates, pos + 1, sum + k * candidates[pos]);
        }

        for (int k = 1; k * candidates[pos] + sum <= target; k++) {
           path.pop_back();
        }
    }
};

